package c.x.jy.wexin.controller;

import c.x.jy.common.annotation.IntoSet;
import c.x.jy.common.annotation.Login;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.dto.OrderEvaluateEntityDto;
import c.x.jy.dao.entity.OrderEntity;
import c.x.jy.dao.entity.OrderEvaluateEntity;
import c.x.jy.dao.entity.OrderItemsEntity;
import c.x.jy.dao.model.OrderItem;
import c.x.jy.service.service.OrderEvaluateService;
import c.x.jy.service.service.OrderItemsService;
import c.x.jy.service.service.OrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 会员评价表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-25 10:50:33
 */
@RestController
@RequestMapping("wechat/orderevaluate")
public class OrderEvaluateController {
    @Autowired
    private OrderEvaluateService orderEvaluateService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderItemsService orderItemsService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderEvaluateService.queryPage(params);

        return R.put(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		OrderEvaluateEntity orderEvaluate = orderEvaluateService.getById(id);

        return R.put(orderEvaluate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderEvaluateEntity orderEvaluate){
        orderEvaluateService.save(orderEvaluate);

        return R.ok();
    }

    //评价
    @Login
    @RequestMapping("/evaluate")
    public R evaluate(@RequestBody OrderEvaluateEntity orderEvaluate){
        if(orderEvaluate==null){
            return R.error("订单有误");
        }
        Long orderId = orderEvaluate.getOrderId();
        if(orderId==null){
            return R.error("订单号错误");
        }
        orderEvaluateService.evaluate(orderEvaluate);

        return R.ok();
    }

    //根据专家ID获取评价信息
    @IntoSet(Includefields={"memberNickName","memberImage"})
    @Login
    @RequestMapping("/getByTeacherId")
    public R getByTeacherId(Long teacherId){
        List<OrderEvaluateEntityDto> list = orderEvaluateService.getByTeacherId(teacherId);
        return R.put(list);
    }

}

